/*
 * @Author: 谢小康 2170673706@qq.com
 * @Date: 2023-11-21 11:55:44
 * @LastEditors: 谢小康 2170673706@qq.com
 * @LastEditTime: 2024-01-28 19:39:14
 * @FilePath: \My-bolg\server\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
const express = require('express');
const bodyParser = require('body-parser');
const article = require('./router/article.js');
const config = require('./router/config.js');
const user = require('./router/users.js');
const upload = require('./router/upload.js');
const lable = require('./router/lable.js');
const shuoshuo = require('./router/shuoshuo.js');
const photo = require('./router/photo.js');
const friend = require('./router/friend.js');
const comment = require('./router/comment.js');
const cors = require('cors');
const app = express();

app.use(cors())
// 配置解析 application/json 格式数据的中间件
app.use(express.json());
// 配置解析 application/x-www-form-urlencoded 格式数据的内置中间件
app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json());
// 设置跨域和相应数据格式 
app.all('*', function(req, res, next) {
	res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type, Authorization');
    res.setHeader("Access-Control-Expose-Headers",["access_token","refresh_token"]) /*  将响应头token加入白名单，供外界操作获取 */
	if (req.method == 'OPTIONS') {
 		/*让options请求快速返回*/
		res.sendStatus(200)
	} else {
		next()
	}
})

app.use('/api/article',article)
app.use("/api/config",config)
app.use("/api/user",user)
app.use("/api/upload",upload)
app.use("/api/lable",lable)
app.use("/api/shuoshuo",shuoshuo)
app.use("/api/photo",photo)
app.use("/api/friend",friend)
app.use("/api/comment",comment)
module.exports = app;